# cython: language_level=3
import os

from dotenv import load_dotenv
from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app.db.sql.operator import get_operator_by_credit_code
from app.db.sql.resource import get_resources_by_credit_code
from app.schemas.platform import SendResourcesRequest, SendAgentMerchantsRequest
from common.database import get_db
from common.http import error_response, ok_response

router = APIRouter(tags=["platform-registration"])
router.prefix = "/v2"
load_dotenv()
CREDIT_CODE = os.getenv("CREDIT_CODE")


@router.post("/sendAgentMerchants")
def send_agent_merchants(
        payload: SendAgentMerchantsRequest, db: Session = Depends(get_db)
):
    """
    2.1
    负荷聚合商代理用户上报接口
    """
    operators = get_operator_by_credit_code(db, payload.creditCode)

    if operators is None:
        return error_response(5000, "creditCode不正确")
    else:
        return ok_response(data=temp_json_data)


@router.post("/sendResources")
def send_resources(payload: SendResourcesRequest, db: Session = Depends(get_db)):
    """
    2.2
    负荷聚合商可调节资源台账上报
    """
    resources = get_resources_by_credit_code(
        db, payload.creditCode, payload.page, payload.pageSize
    )
    return ok_response(resources)
